//
//  LCShengJingTextViewController+LCSetupHeaderView.m
//  JKFuYinProject
//
//  Created by admin on 2018/1/8.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LCShengJingTextViewController+LCSetupHeaderView.h"
#import "LCShengJingNativeSelectViewController.h"
#import "TheHomeManager+Additions.h"
#import "LCHistoryDataManager.h"

@implementation LCShengJingTextViewController (LCSetupHeaderView)

#pragma mark -  top  -
//点击选择器 - 圣经名字触发事件
- (void)nameAction:(UIButton *)btn{
    [btn setTitleColor:JK_HUISE_LINE_COLOR forState:UIControlStateNormal];
    btn.backgroundColor = JK_RED_COLOR;
    
    LCShengJingNativeSelectViewController * shengJVC = [[LCShengJingNativeSelectViewController alloc] init];
    NSString *str = [LCHistoryDataManager loadBibleTextTitleData];
    NSString *selectName = [str substringWithinBoundsLeft:@"约" right:@"("];
    shengJVC.selectIndex = 0;
    shengJVC.nameStr = selectName;//给选择器传 标题
    //    获取
    NSInteger tempCount = [[TheHomeManager shareTheHomeManager] getZhangJieNumWithSelectTitle:selectName];
    shengJVC.numCount = tempCount;//给选择器传 第几章节
    [self presentViewController:shengJVC animated:YES completion:nil];
}
- (void)countAction:(UIButton *)btn{
    [btn setTitleColor:JK_HUISE_LINE_COLOR forState:UIControlStateNormal];
    btn.backgroundColor = RGBColor(228, 83, 77);
    //    获取
    NSString *str = [LCHistoryDataManager loadBibleTextTitleData];
    NSString *selectName = [str substringWithinBoundsLeft:@"约" right:@"("];

    LCShengJingNativeSelectViewController * shengJVC = [[LCShengJingNativeSelectViewController alloc] init];
    //    获取
    shengJVC.selectIndex = 1;
    shengJVC.nameStr = selectName;
    NSInteger tempCount = [[TheHomeManager shareTheHomeManager] getZhangJieNumWithSelectTitle:selectName];
    shengJVC.numCount = tempCount;
    [self presentViewController:shengJVC animated:YES completion:nil];
}
//正常
- (void)changeColor:(UIButton *)btn{
    [btn setTitleColor:JK_HUISE_LINE_COLOR forState:UIControlStateNormal];
    btn.backgroundColor = JK_RED_COLOR;
}
//高亮
- (void)changeColor1:(UIButton *)btn {
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.backgroundColor = JK_HUISE_LINE_COLOR;
}
- (void)setupNV{
    
    UIView * titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 170, 30)];
    titleView.layer.masksToBounds = YES;
    titleView.layer.cornerRadius = 4;
    titleView.layer.borderWidth = 1.1;
    titleView.layer.borderColor = JK_RED_COLOR.CGColor;
    
    self.nameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nameBtn.frame = CGRectMake(0, 0, titleView.width/5*3, titleView.height);
    self.nameBtn.tag = 7778;
    [self.nameBtn addTarget:self action:@selector(nameAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.nameBtn addTarget:self action:@selector(changeColor1:) forControlEvents:UIControlEventTouchDown];
    [self.nameBtn addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpOutside];
    [self.nameBtn setTitleColor:JK_HUISE_COLOR forState:UIControlStateNormal];
    self.nameBtn.backgroundColor = JK_RED_COLOR;
    self.nameBtn.titleLabel.font = FONT_14;
    [titleView addSubview:self.nameBtn];
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(self.nameBtn.right, 0, 1, titleView.height)];
    lineView.backgroundColor = JK_HUISE_COLOR;
    [titleView addSubview:lineView];
    
    self.countBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.countBtn.frame = CGRectMake(self.nameBtn.right+1, 0, titleView.width/5*2-1, titleView.height);
    self.countBtn.tag = 7779;
    [self.countBtn setTitleColor:JK_HUISE_COLOR forState:UIControlStateNormal];
    //    self.countBtn.backgroundColor = JK_RED_COLOR;
    self.countBtn.titleLabel.font = FONT_14;
    [self.countBtn addTarget:self action:@selector(countAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.countBtn addTarget:self action:@selector(changeColor1:) forControlEvents:UIControlEventTouchDown];
    [self.countBtn addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpOutside];
    [titleView addSubview:self.countBtn];
    self.navigationItem.titleView = titleView;
}
#pragma mark -  加载top和header数据  -
-(void)loadTopAndHeaderData{
    NSString *tabNameStr = [[LCHistoryDataManager loadBibleTextTitleData] substringWithinBoundsLeft:@"约" right:@"("];
    NSString *countStr = [[LCHistoryDataManager loadBibleTextTitleData] substringWithinBoundsLeft:@"第" right:@"章"];
    [self.nameBtn setTitle:tabNameStr forState:UIControlStateNormal];
    [self.countBtn setTitle:countStr forState:UIControlStateNormal];
    self.numLabel.text = [NSString stringWithFormat:@"第 %@ 章", countStr];
    self.tabNameLabel.attributedText = [[NSAttributedString alloc] initWithString:tabNameStr];
}
- (void)setupHeaderView{
    
#pragma mark -  headerView  标题  -
    UIView * headerView = [[UIView alloc] init];
    self.bigTitleView = headerView;
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 0;// 字体的行间距
    
    UILabel *tabNameLabel = [[UILabel alloc] init];
    self.tabNameLabel = tabNameLabel;
    tabNameLabel.textAlignment = NSTextAlignmentCenter;
    tabNameLabel.font = [UIFont systemFontOfSize:30.0];
    [headerView addSubview:tabNameLabel];
    
    self.numLabel = [[UILabel alloc] init];
    self.numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel.font = [UIFont systemFontOfSize:16.0];
    [headerView addSubview:self.numLabel];
    tabNameLabel.frame = CGRectMake(0, 30, self.view.width, 30);
    self.numLabel.frame = CGRectMake(0, tabNameLabel.bottom, tabNameLabel.width, 30);
    self.bigTitleView.frame = CGRectMake(0, 0, ScreenWidth, 100);
    self.bibleTableViewController.tableView.tableHeaderView = self.bigTitleView;
}

@end
